<template>
  <div class="comment">
    <div class="comment-item">
      <div class="photo">
        <el-avatar :src="item.avatar_url" size="40" />
      </div>
      <div class="right">
        <div class="name">{{ item.nick_name }}</div>
        <div v-if="item.comment_id" class="content">
          回复@{{ item.reply_user_name }}：{{ item.content }}
        </div>
        <div v-else class="content">{{ item.content }}</div>
        <div class="parent">
          <el-row class="img" type="flex">
            <el-image v-for="image in item.attach_url" :key="image" :src="image" />
          </el-row>
        </div>
        <div class="bar">
          <div class="time">{{ item.create_time }}</div>
          <div class="delete" @click="deleteComment(item.id)">删除</div>
          <!--<div class="comment" @click="handleOpen"><i class="edu-icon-pinglun edu-icon&#45;&#45;left" />{{ item.like }}</div>-->
        </div>
      </div>
    </div>
    <!--<template v-if="show">-->
    <!--  <comment-item v-for="sub in item.child" :key="sub.id" :item="sub" class="sub-item" />-->
    <!--</template>-->
  </div>
</template>

<script>
export default {
  name: 'CommentItem',
  inject: ['reload'],
  props: {
    item: {
      type: Object,
      default: _ => {
        return {};
      }
    }
  },
  // data() {
  //   return {
  //     // show: false
  //   }
  // },
  methods: {
    deleteComment(id) {
      this.$box
          .confirm('确认删除该评论吗')
          .then(() => {
            this.$http.delete(
                '/circle/admin/comment/' + id + '/delete',
                {},
                response => {
                  this.$message.success(response.msg, _ => {
                    this.reload();
                  });
                },
                error => {
                  this.$message.error(error.msg);
                }
            );
          })
          .catch(() => {});
    }
    // handleOpen() {
    //   this.show = !this.show
    // }
  }
}
</script>

<style lang="scss" scoped>
.comment-item {
  display: flex;
  padding-top: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #ebeef5;
  .right {
    padding-top: 9px;
    flex: 1;
    margin-left: 14px;
  }
  .name {
    font-size: 13px;
    font-weight: 400;
    color: #606266;
  }
  .content {
    margin-top: 10px;
    font-size: 14px;
    font-weight: 400;
    color: #303133;
    line-height: 24px;
  }
  .bar {
    margin-top: 20px;
    display: flex;
    font-size: 12px;
    font-weight: 400;
    color: #606266;
  }
  .delete {
    margin-left: 20px;
    cursor: pointer;
  }
  .comment {
    margin-left: auto;
    display: flex;
    align-items: center;
  }
  .parent {
    margin-top: 5px;
    display: flex;
    flex-wrap: wrap;
    margin-left: -5px;
    margin-right: -5px;
    .img {
      padding: 5px;
      .el-image {
        margin-right: 5px;
        display: block;
        height: 120px;
        width: 120px;
      }
    }
  }
}
.sub-item {
  margin-left: 54px;
}
</style>
